package server.controller.commentController;

import server.entity.Comment;
import server.entity.Evaluation;
import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addComment")
public class AddCommentServlet extends HttpServlet {
    private static final long serialVersionUID = 8826277306717113601L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Info info = null;
        Integer userId = (Integer) req.getAttribute("userId");

        Comment comment = MyUtils.convertRequest2Bean(req, Comment.class);
        comment.setUserId(userId);

        info = ModelFactory.getCommentModel().addComment(comment);

        ResponseUtil.responseMessage(resp, info);
    }
}